import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import VueHighlightJS from 'vue-highlightjs'
import axios from 'axios'
import 'normalize.css'
import './assets/css/global.scss'
import 'highlight.js/styles/atelier-estuary-light.css'

// 设置请求base_url
axios.defaults.baseURL = 'http://127.0.0.1:7001/'
// 设置拦截器
axios.interceptors.request.use(config => {
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})

// 全局路由拦截
router.beforeEach((to, from, next) => {
  if (to.meta.requiresAuth) {
    const token = window.sessionStorage.getItem('token')
    if (token) {
      next()
    } else {
      next({
        path: '/login'
      })
    }
  } else {
    next()
  }
})

Vue.prototype.$axios = axios
Vue.config.productionTip = false
Vue.use(VueHighlightJS)

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
